package com.example.controller;

import com.example.bean.Equipment;
import com.example.service.EquipmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "器材管理模块",description = "器材的查询、添加、删除、保修、租借、回收、价格表")
@RequestMapping("/Equipment")
@Controller
public class EquipmentController {

    @Autowired
    EquipmentService equipmentService;
//
//    @ApiOperation("器材分页查询")   //接口描述
//    @RequestMapping(value = "/query-equipment", method = RequestMethod.GET)
//    public String queryEquipment(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
//                                 @RequestParam(value = "pageSize", required = false, defaultValue = "5") Integer pageSize,
//                                 Model model){
//        PageInfo<Equipment> equipmentPageInfo = equipmentService.queryEquipment(pageNum, pageSize);
//        model.addAttribute("equipmentPageInfo", equipmentPageInfo);
//        return "redirect:/page/equipment";
//    }

    @ApiOperation("器材查询")   //接口描述
    @RequestMapping(value = "/select-equipment", method = RequestMethod.GET)
    @ResponseBody
    public List<Equipment> selectEquipment(@RequestParam("equipmentName") String equipmentName){
        return equipmentService.selectByName(equipmentName);
    }

    @ApiOperation("个人器材查询")   //接口描述
    @RequestMapping(value = "/select-getmyequ", method = RequestMethod.GET)
    @ResponseBody
    public List<Equipment> getMyEqu(@RequestParam("userId") int userId){
        return equipmentService.selectByUserId(userId);
    }

    @ApiOperation("维修器材查询")   //接口描述
    @RequestMapping(value = "/select-getrepair", method = RequestMethod.GET)
    @ResponseBody
    public List<Equipment> getRepair(){
        return equipmentService.getRepair();
    }

    @ApiOperation("器材购置新增")   //接口描述
    @RequestMapping(value = "/add-equipment", method = RequestMethod.POST)
    @ResponseBody
    public void addEquipment(@RequestBody Equipment equipment){
        equipmentService.addEquipment(equipment);
    }

    @ApiOperation("器材报废删除")   //接口描述
    @RequestMapping(value = "/delete-equipment", method = RequestMethod.POST)
    @ResponseBody
    public String deleteEquipment(@RequestParam("equipmentId") int equipmentId){
        return equipmentService.deleteEquipment(equipmentId) ? "success" : "该器材正在使用或维修中，不能删除";
    }

    @ApiOperation("器材维护报修")   //接口描述
    @RequestMapping(value = "/repair-equipment", method = RequestMethod.POST)
    @ResponseBody
    public void repairEquipment(@RequestParam("equipmentId") int equipmentId, @RequestParam("userId") int userId){
        equipmentService.repairEquipment(equipmentId, userId);
    }

    @ApiOperation("器材租用")   //接口描述
    @RequestMapping(value = "/rent-equipment", method = RequestMethod.POST)
    @ResponseBody
    public void rentEquipment(@RequestParam("equipmentId") int equipmentId, @RequestParam("userId") int userId){
        equipmentService.rentEquipment(equipmentId, userId);
    }

    @ApiOperation("器材回收")   //接口描述
    @RequestMapping(value = "/recovery-equipment", method = RequestMethod.POST)
    @ResponseBody
    public void recoveryEquipment(@RequestParam("equipmentId") int equipmentId){
        equipmentService.recoveryEquipment(equipmentId, 0);
    }
//
//    @ApiOperation("器材租用收费标准查询")   //接口描述
//    @RequestMapping(value = "/charge-equipment", method = RequestMethod.GET)
//    public String chargeEquipment(@RequestParam("equipmentId") String equipmentId){
//        equipmentService.chargeEquipment(Integer.parseInt(equipmentId));
//        return "redirect:/page/equipment";
//    }
//
//    @ApiOperation("器材租用时间")   //接口描述
//    @RequestMapping(value = "/time", method = RequestMethod.GET)
//    @ResponseBody
//    public List<Equipment> time(){
//        return equipmentService.selectTime();
//    }
}
